pkg_check_modules(LIBUDEV REQUIRED libudev)
include_directories(${LIBUDEV_INCLUDE_DIRS})
pkg_check_modules(DBUS_GLIB REQUIRED dbus-glib-1)
include_directories(${DBUS_GLIB_INCLUDE_DIRS})

add_library(usb_media usb_media.c)
target_link_libraries(usb_media syncup ${LIBUDEV_LIBRARIES} ${GLIB2_LIBRARIES})

find_program(DBUS_BINDING_TOOL dbus-binding-tool)
add_custom_command(
	OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/syncup-service-glue.h
	COMMAND ${DBUS_BINDING_TOOL} --prefix=syncup_service --mode=glib-server
		--output=${CMAKE_CURRENT_BINARY_DIR}/syncup-service-glue.h
		${CMAKE_CURRENT_SOURCE_DIR}/syncup-service.xml
	COMMAND ${CMAKE_COMMAND} -E copy_if_different
		${CMAKE_CURRENT_BINARY_DIR}/syncup-service-glue.h
		${CMAKE_CURRENT_SOURCE_DIR}/syncup-service-glue.h
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/syncup-service.xml
	)
add_custom_target(syncup-service-glue_h
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/syncup-service-glue.h)
add_custom_command(
	OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/syncup-service-bindings.h
	COMMAND ${DBUS_BINDING_TOOL} --mode=glib-client
		--output=${CMAKE_CURRENT_BINARY_DIR}/syncup-service-bindings.h
		${CMAKE_CURRENT_SOURCE_DIR}/syncup-service.xml
	COMMAND ${CMAKE_COMMAND} -E copy_if_different
		${CMAKE_CURRENT_BINARY_DIR}/syncup-service-bindings.h
		${CMAKE_CURRENT_SOURCE_DIR}/syncup-service-bindings.h
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/syncup-service.xml
	)
add_custom_target(syncup-service-bindings_h
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/syncup-service-bindings.h)
#add_library(syncup-service syncup-service.c syncup-service-glue.h)
#target_link_libraries(syncup-service ${GLIB2_LIBRARIES} ${DBUS_GLIB_LIBRARIES})


set(FSNOTIFY_EXTRA_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/fsnotify.c PARENT_SCOPE)

set(SYNCUP_EXTRA_INCLUDE
	${CMAKE_CURRENT_SOURCE_DIR}
	${DBUS_GLIB_INCLUDE_DIRS} PARENT_SCOPE)
set(SYNCUP_EXTRA_GEN_SRCS
	${CMAKE_CURRENT_SOURCE_DIR}/syncup-service-glue.h PARENT_SCOPE)
set(SYNCUP_EXTRA_SRCS
	${CMAKE_CURRENT_SOURCE_DIR}/syncup.c
	${CMAKE_CURRENT_SOURCE_DIR}/syncup-service.c
	${SYNCUP_EXTRA_GEN_SRCS}
	PARENT_SCOPE)
set(SYNCUP_EXTRA_DEPENDS syncup-service-glue_h PARENT_SCOPE)
set(SYNCUP_EXTRA_LIBS ${DBUS_GLIB_LIBRARIES} PARENT_SCOPE)

add_subdirectory(test)
